<template>
  <div id="app">
    <router-view></router-view>

    <!-- 底部 -->
    <div class="TopBar">
      <span
        @click="handlerClick('首页', '/index')"
        :class="{ active: index == '首页' }"
      >
        <van-icon name="wap-home-o" />
        <p>首页</p>
      </span>
      <span
        @click="handlerClick('会员', '/vip')"
        :class="{ active: index == '会员' }"
        ><van-icon name="user-circle-o" />
        <p>会员</p></span
      >
      <span
        @click="handlerClick('购物车', '/Car')"
        :class="{ active: index == '购物车' }"
      >
        <van-icon name="shopping-cart-o" v-if="carCount == 0" />
        <van-icon name="shopping-cart-o" :badge="carCount" v-else />
        <p>购物车</p></span
      >
      <span
        @click="handlerClick('搜索', '/search')"
        :class="{ active: index == '搜索' }"
      >
        <van-icon name="search" />
        <p>搜索</p></span
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      carCount: 0,
      index: "首页",
    };
  },
  methods: {
    handlerClick(value, path) {
      this.index = value;
      this.$router.push({ path: path }).catch((err) => {});
    },
  },
};
</script>

<style lang="less" scoped>
.app {
  width: 100%;
}
.TopBar {
  width: 100%;
  height: 50px;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background-color: #f7f7f7;
  span {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
  }
  .active {
    color: #0099ff;
  }
}
</style>
